import { Column, Entity, ManyToMany } from 'typeorm'
import { CommonEntity } from '../common.entity'
import { RoleEntity } from './role.entity'

@Entity('sys_menu')
export class MenuEntity extends CommonEntity {
  @Column({ comment: '上级菜单', default: '0' })
  parentId: string

  @Column({ comment: '路由地址', default: null })
  path: string

  @Column({ comment: '组件路径', default: null })
  component: string

  @Column({ comment: '类型（M目录 C菜单 F按钮）', default: 'M' })
  type: string

  @Column({ comment: '菜单图标', default: null })
  icon: string

  @Column({ comment: '菜单名称', default: null })
  title: string

  @Column({ comment: '菜单是否可见', default: 1, type: 'tinyint' })
  visible: number

  @Column({ comment: '是否一级路由', default: 0, type: 'tinyint' })
  full: number

  @Column({ comment: '是否缓存组件', default: 0, type: 'tinyint', name: 'is_cache' })
  isCache: number

  @Column({ comment: '权限字符', default: null })
  permission: string

  /** 数据状态（1正常，0停用） */
  @Column({ type: 'tinyint', comment: '数据状态', default: 1 })
  status: number

  @Column({ comment: '显示顺序', type: 'int', default: 1 })
  order: number

  @ManyToMany(() => RoleEntity, (role) => role.menus, { onDelete: 'CASCADE' })
  roles: RoleEntity[]
}
